﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Streambolics.Gui;
using Streambolics.Notes;

namespace DemoApp
{
    public partial class MainForm : StandardForm
    {
        private Connection _Connection;

        public MainForm ()
        {
            InitializeComponent ();
            RegisterAsMain ();
        }

        private void button_Connect_Click (object sender, EventArgs e)
        {
            _Connection = edit_Password.Connect ();
            EnableDisable ();
            
        }

        private void MainForm_Load (object sender, EventArgs e)
        {
            EnableDisable ();
        }

        private void EnableDisable ()
        {
            button_Connect.Enabled = !String.IsNullOrEmpty (edit_Password.Password);
            button_Explore.Enabled = !String.IsNullOrEmpty (edit_Database.Text) && _Connection != null;
        }

        private void button_Explore_Click (object sender, EventArgs e)
        {
            if (edit_Database.Text == "MOMA")
            {
                tree_Views.SetDatabase (new MomaDatabase (_Connection, edit_Server.Text));
            }
            else
            {
                tree_Views.SetDatabase (_Connection.Open (edit_Server.Text, edit_Database.Text));
            }
            EnableDisable ();
        }

        private void edit_Database_TextChanged (object sender, EventArgs e)
        {
            EnableDisable ();
        }

        private void tree_Views_SelectionChanged (object sender, EventArgs e)
        {
            list_Documents.SetDocuments (tree_Views.Selected);
        }


        private void edit_Password_PasswordChanged (object sender, EventArgs e)
        {
            EnableDisable ();
        }

        private void list_Documents_SelectionChanged (object sender, EventArgs e)
        {
            list_Items.SetDocument (list_Documents.Selected);
        }

    }
}
